package com.gp.gback.system.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by honghua.dong1 on 16/12/14.
 * 值为List的map，put时如果values为nulls时，new List,否则add
 * @param <K> 键
 */
public class ListMap<K,T> extends HashMap<K,List<T>> {

    public List put(K key, List<T> value) {
        if(!this.containsKey(key)) {
            List list = new ArrayList();
            super.put(key,list);
        }
        List<T> resultList = super.get(key);
        resultList.addAll(value);
        return resultList;
    }

    @Override
    public List<T> get(Object key) {
        if(!this.containsKey(key)) {
            super.put((K) key,new ArrayList<T>());
        }
        return super.get(key);
    }
}
